﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Ndo.Maths
{
    public class UInteger32 : Integer<UInteger32>
    {
        public UInteger32()
            : this(1)
        { }
        [Ndo.Text.ParsingPattern(@"(\+|-)?\d+")]
        public UInteger32(string text)
            : this(UInt32.Parse(text))
        { }
        public UInteger32(UInt32 i)
        {
            value = i;
        }

        private readonly UInt32 value;
        public static implicit operator UInteger32(UInt32 i)
        {
            return new UInteger32(i);
        }
        public static UInteger32 operator +(UInteger32 i1, UInteger32 i2)
        {
            return new UInteger32((UInt32)(i1.value + i2.value));
        }
        public static UInteger32 operator -(UInteger32 i1, UInteger32 i2)
        {
            return new UInteger32((UInt32)(i1.value - i2.value));
        }
        public static UInteger32 operator *(UInteger32 i1, UInteger32 i2)
        {
            return new UInteger32((UInt32)(i1.value * i2.value));
        }
        public static UInteger32 operator /(UInteger32 i1, UInteger32 i2)
        {
            return new UInteger32((UInt32)(i1.value / i2.value));
        }
        public static UInteger32 operator %(UInteger32 i1, UInteger32 i2)
        {
            return new UInteger32((UInt32)(i1.value % i2.value));
        }
        public static bool operator ==(UInteger32 i1, UInteger32 i2)
        {
            return i1.value == i2.value;
        }
        public static bool operator !=(UInteger32 i1, UInteger32 i2)
        {
            return i1.value != i2.value;
        }

        public override bool Equals(object obj)
        {
            if (obj is UInteger32)
                return this.value == ((UInteger32)obj).value;
            return false;
        }
        public override int GetHashCode()
        {
            return value.GetHashCode();
        }
        public override string ToString()
        {
            return value.ToString();
        }

        public override int CompareTo(UInteger32 other)
        {
            return value.CompareTo(other.value);
        }

        public override SignTypes Sign
        {
            get
            {
                if (value == 0)
                    return SignTypes.Zero;
                return SignTypes.Positive;
            }
        }
    }
}
